<template>
  <div class="m-page-container">
    <div class="detail flex-left" v-if="!simple">
      <el-pagination
        background
        small
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        :current-page="currentPageNum"
        :page-size="pageSize"
        :page-sizes="[10,20,30]"
        layout="total,jumper"
        :total="total"
        :pager-count="5"
      ></el-pagination>
      <div class="confirm">{{$t('page.confirm')}}</div>
    </div>
    <div class="simple">
      <el-pagination
        background
        small
        @current-change="handleCurrentChange"
        :current-page="currentPageNum"
        :page-size="pageSize"
        :page-sizes="[10,20,30]"
        layout="prev,pager,next"
        :total="total"
        :pager-count="5"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  name: "pages",
  components: {},
  data() {
    return {
      currentPageNum: this.currentPage,
      firstPageBtnDisabled: true,
      lastPageBtnDisabled: false
    };
  },
  props: {
    currentPage: {
      type: Number,
      default: 1
    },
    pageSize: {
      type: Number,
      default: 10
    },
    total: {
      type: Number,
      default: 0
    },
    simple: {
      type: Boolean,
      default: true
    }
  },
  watch: {
    currentPage(newVal) {
      this.currentPageNum = newVal;
      this.firstPageBtnDisabled = this.currentPageNum === 1 ? true : false;
      this.lastPageBtnDisabled =
        this.currentPageNum === this.lastPageNum ? true : false;
    }
  },
  computed: {
    lastPageNum() {
      return Math.ceil(this.total / this.pageSize);
    }
  },
  methods: {
    handleCurrentChange(page) {
      this.firstPageBtnDisabled = page === 1 ? true : false;
      this.lastPageBtnDisabled = page === this.lastPageNum ? true : false;
      this.currentPageNum = page;
      this.$emit("pageChange", page);
    },
    handleSizeChange(size) {
      this.$emit("sizeChange", size);
    }
  }
};
</script>
<style lang="scss">
.m-page-container {
  .el-pagination {
    .el-pager li:not(.disabled).active {
      background-color: $blue;
    }
    .el-pager li {
      font-weight: 500;
      font-size: 12px;
    }
  }
  .confirm {
    flex-shrink: 1;
    margin-left: 10px;
    display: inline-block;
    width: 45px;
    height: 22px;
    line-height: 22px;
    background: $blue;
    border-radius: 15px;
    text-align: center;
    color: $white;
    font-size: 12px;
    font-family: PingFangSC-Regular;
    cursor: pointer;
  }
  .el-pagination {
    padding: 0;
  }
  .el-pagination__jump {
    margin-left: 0;
    .el-input__inner {
      font-size: 12px;
    }
  }
  .el-pagination__sizes {
    margin: 0;
    .el-input {
      width: 84px;
      .el-input__inner {
        height: 22px;
        line-height: 22px;
        font-size: 12px;
      }
    }
  }
  .el-pagination__total {
    margin: 0;
    font-size: 12px;
    font-family: PingFangSC;
    font-weight: 400;
    color: rgba(128, 147, 167, 1);
    line-height: 17px;
  }
  .detail {
    margin-bottom: 12px;
  }
  .first-pager,
  .last-pager {
    background: #f4f4f5;
  }
}
</style>